/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RevCentipede.java
 *
 * Created on Feb 25, 2009, 4:17:46 PM
 */

/**
 *
 * @author Himanshu  Sharma
 */
import java.util.*;
import java.awt.event.MouseListener ;
import java.awt.event.MouseEvent ;
import java.awt.event.InputEvent ;
public class Rev_Centipede extends javax.swing.JFrame {
    Double money;
    Double money_Won;
    Game G;

    int count = 0, disable=0, go=0;
    Random generator;

    /** Creates new form RevCentipede */
    public Rev_Centipede( double money) {
        this.money = money ;
        initComponents();
        G = new Game();
        l4.setText(Double.toString(money));
        this.setVisible(true);
            addMouseListener( new Rev_Centipede.CheckMouse() ) ;
    }

    
    public Rev_Centipede() {
        money = 5.00 ;
        initComponents();
        G = new Game();
        l4.setText(Double.toString(money));
        this.setVisible(true);
            addMouseListener( new Rev_Centipede.CheckMouse() ) ;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        l1 = new javax.swing.JLabel();
        l2 = new javax.swing.JLabel();
        l3 = new javax.swing.JLabel();
        l5 = new javax.swing.JLabel();
        b1 = new javax.swing.JButton();
        b2 = new javax.swing.JButton();
        l4 = new javax.swing.JLabel();
        l6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        l1.setText("Centipede");

        l2.setText("You are player 2");

        l3.setText("Player 1 passed $");

        l5.setText("What would you like to do");

        b1.setText("Pass");
        b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b1ActionPerformed(evt);
            }
        });

        b2.setText("Stop");
        b2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b2ActionPerformed(evt);
            }
        });

        l4.setText("5");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(321, 321, 321)
                        .addComponent(l1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(304, 304, 304)
                        .addComponent(l2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(273, 273, 273)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(l5))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(l3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(252, 252, 252)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(l6, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(b1)
                                .addGap(92, 92, 92)
                                .addComponent(b2)))))
                .addContainerGap(248, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(l2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l3)
                    .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(l5)
                .addGap(18, 18, 18)
                .addComponent(l6, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b2)
                    .addComponent(b1))
                .addContainerGap(119, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents




    private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
          if (disable ==0) {
                generator = new Random();
                int choice;
                choice = generator.nextInt(3) ;
                if(choice==2){
                     l6.setText("<html><p>Player 1 accepted $" + money + " <p>You Lost!!!</html>");
                     money_Won = 0.0;
                     disable =1;
                     go=1;

                     money_Won = 0.0 ;
                     b1.setVisible(false);
                     b2.setText("Next");

                     

                 }
                 else{
                    money = money + 2 ;
                    l4.setText("$" + Double.toString(money));
                    l6.setText("Player 1 passed what'd you like to do?");
                    count = count+1 ;
                    if ( count == 5 ) {
                        l2.setText("");
                        l1.setText("");
                        l1.setText("Time Out!!!") ;
                        l3.setText("");
                        money_Won = 0.0;
                        b1.setVisible(false);
                        b2.setText("Next");

                    }

            }
    }

}//GEN-LAST:event_b1ActionPerformed

    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b2ActionPerformed
            go++;

                        if(b2.getText().equals("Next")){

                G.writeLog("Centipede_Player2_verion: $ " + money_Won);
                setVisible(false);
                G.free = true;


            }// TODO add your handling code here:

            if(b2.getText().equals("Stop")) {
                money_Won = money ;
                l1.setText("You won $" + money_Won);
                l2.setText("");
                l3.setText("");
                l4.setText("");
                l6.setText("");
                l5.setText("") ;

                disable=1;
                go++;


                b1.setVisible(false);
                b2.setText("Next");

            }

}//GEN-LAST:event_b2ActionPerformed

    @Override
    public synchronized void addMouseListener(MouseListener l) {
        super.addMouseListener(l);
    }
    class CheckMouse implements MouseListener{
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}

        public void mouseClicked(MouseEvent e) {
            int modifiers = e.getModifiers();
            if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {}
                if (disable ==0) {
                generator = new Random();
                int choice;
                choice = generator.nextInt(3) ;
                if(choice==2){
                     l6.setText("<html><p>Player 1 accepted $" + money + " <p>You Lost!!!</html>");
                     money_Won = 0.0;
                     disable =1;
                     go=1;

                     money_Won = 0.0 ;
                     b1.setVisible(false);
                     b2.setText("Next");



                 }
                 else{
                    money = money + 2 ;
                    l4.setText("$" + Double.toString(money));
                    l6.setText("Player 1 passed what'd you like to do?");
                    count = count+1 ;
                    if ( count == 5 ) {
                        l2.setText("");
                        l1.setText("");
                        l1.setText("Time Out!!!") ;
                        l3.setText("");
                        money_Won = 0.0;
                        b1.setVisible(false);
                        b2.setText("Next");

                    }

            }
    }

            if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {}
            if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
                        go++;

                        if(b2.getText().equals("Next")){

                G.writeLog("Centipede_Player2_verion: $ " + money_Won);
                setVisible(false);
                G.free = true;


            }// TODO add your handling code here:

            if(b2.getText().equals("Stop")) {
                money_Won = money ;
                l1.setText("You won $" + money_Won);
                l2.setText("");
                l3.setText("");
                l4.setText("");
                l6.setText("");
                l5.setText("") ;

                disable=1;
                go++;


                b1.setVisible(false);
                b2.setText("Next");

            }


            }
        }
        

    }
/**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Rev_Centipede().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b1;
    private javax.swing.JButton b2;
    private javax.swing.JLabel l1;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l5;
    private javax.swing.JLabel l6;
    // End of variables declaration//GEN-END:variables

}
